'use strict';

const { log } = require("console");

const db = uniCloud.database()
const dbCmd = db.command
exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)
	const {mobile,password} = event
	// 链接云空间的template-user 名
	const collection = db.collection('template-user')
	// 新增add 接口  云函数
	// username: dbCmd.or(dbCmd.eq('tianyizheng'),dbCmd.eq('小刘同学'))
	const res = await collection.where({
		mobile:'18888888888',
		password:'123456',
		// mobile:'15753823552',
		// password:'123456',
		}).get()
	const res1 = await collection.doc(res.data[0]['_id']).get()
	//返回数据给客户端
	if(res1.data.length > 0 && res1.data[0].token){
		return {
			code:200,
			data:res1.data[0],
			msg:"登录成功"
		}
	}else{
		return {
			code:500,
			msg:"登录失败"
		}
	}
	
};
